package realm.inorder.itmill.ui.panel.logged;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import realm.inorder.itmill.controller.DefaultController;
import realm.inorder.itmill.session.SessionContext;
import realm.inorder.itmill.ui.panel.logged.cadastro.cliente.ClienteCadastroPanel;
import realm.inorder.itmill.ui.panel.logged.cadastro.cliente.ClienteConsultaPanel;
import realm.inorder.itmill.ui.panel.logged.cadastro.produto.ProdutoPanel;
import realm.inorder.persistence.model.Cliente;

import com.itmill.toolkit.ui.Layout;

@Controller
public class LoggedLayoutController extends DefaultController {

	@Autowired
	private LoggedLayout loggedLayout;

	@Autowired
	private HomePanel homePanel;
	
	@Autowired
	private ClienteCadastroPanel clienteCadastroPanel;
	
	@Autowired
	private ClienteConsultaPanel clienteConsultaPanel;
	
	@Autowired
	private ProdutoPanel produtoPanel;
	
	private void changeContentPanel(com.itmill.toolkit.ui.Component component) {
		loggedLayout.changeContentPanel(component);
	}
	
	public void showLoggedLayout(Layout layout) {
		changeContentPanel(homePanel);
		layout.addComponent(loggedLayout);
	}
	
	public void showClienteCadastroPanel() {
		SessionContext.put(Cliente.class, null);
		clienteCadastroPanel.clearComponents();
		changeContentPanel(clienteCadastroPanel);
	}

	public void showClienteConsultaPanel() {
		clienteConsultaPanel.refreshTable();
		changeContentPanel(clienteConsultaPanel);
	}
	
}
